{%include file="index.header.tpl.php"%}
{%include file="index.left.tpl.php"%}
 <!--主要内容开始-->
  <div class="content-wrapper">
    <section class="content">
      <div class="row">
        <section class="col-lg-12 connectedSortable">
         <div class="box box-default box-solid">
             <form action="" method="POST">	
                <div class="box-header with-border">
                    <span class="fa fa-folder-open" style="float:left; font-size:18px; padding-top:3px; color:#3c8dbc;" ></span>
                    <p class="box-title">公开课安排表</p>
                </div>
                <div class="box-body">
                    <h4 class="text-center">公开课安排表</h4>

                    <input type="button" class="btn btn-default" name="xx" onclick="addNewRow();" value="增加行"/>
                    <input type="button" class="btn btn-default" name="yy" onclick="removeRow();" value="删除行" />
                     <table class="table table-bordered"  id="myTab">
                                <thead>
                                    <tr>
                                        <td>选择</td>
									    <td>周次</td>
                                        <td>教师</td>
                                        <td>日期</td>                      
										<td>节次</td>
										<td>班级</td>
                                        <td>教学内容</td>
										<td>科目</td>
										<td>备注</td>
                                    </tr>	
                                </thead>
                                <tbody>
                                {%foreach from=$open_lists item=value%}
                                    <tr>
                                        <td style="width:10%"><input type='checkbox' name='chkArr' id='chkArr'  /></td>
									    <td style="width:10%">
                                            <input type="hidden" name="up[{%$value.open_id%}][open_id]" class="form-control aim" value="{%$value.open_id%}">
                                            <input type="text" name="up[{%$value.open_id%}][open_week_num]" class="form-control" value="{%$value.open_week_num%}">
										</td>
                                        <td style="width:10%">
                                            <select class="form-control" style="padding:0;" name="up[{%$value.open_id%}][staff_id]">
											{%foreach from=$staff_list key=key item=va%}
                                                <option value="{%$va.staff_id%}" {%if $va.staff_id eq $value.staff_id%}selected{%/if%}> {%$va.staff_name%}</option>
                                            {%/foreach%}
                                            </select>
                                        </td>
                                        <td style="width:10%">
										<input type="text" name="up[{%$value.open_id%}][open_time]" class="form-control time" value="{%$value.open_time%}">
										</td>          
										<td style="width:10%">
										<input type="text" name="up[{%$value.open_id%}][open_num]" class="form-control" value="{%$value.open_num%}">
										</td>
										<td style="width:10%">
                                        	 <select class="form-control" name="up[{%$value.open_id%}][class_id]">
											 {%foreach from=$class_list key=key item=va%}
                                                <option value="{%$va.class_id%}" {%if $va.class_id eq $value.class_id%}selected{%/if%}>{%$va.class_name%}</option>
                                             {%/foreach%}
                                            </select>
                                        </td>
                                        <td style="width:10%">
										<input type="text" name="up[{%$value.open_id%}][open_content]" class="form-control" value="{%$value.open_content%}">
										</td>
										<td style="width:10%">
                                        	 <select class="form-control" name="up[{%$value.open_id%}][subject_id]">
											 {%foreach from=$subject_list key=key item=va%}
                                                <option value="{%$va.subject_id%}" {%if $va.subject_id eq $value.subject_id%}selected{%/if%}>{%$va.subject_name%}</option>
                                             {%/foreach%}
                                            </select>
                                        </td>
										<td>
                                            <textarea class="form-control" rows="1" name="up[{%$value.open_id%}][open_remark]" >{%$value.open_remark%}</textarea>
                                        </td>
                                    </tr>
                                {%/foreach%}
                            </tbody>
                        </table>
				   </div><!--box-body -->
                   <div class="box-footer text-center">
				         <button type="submit" class="btn btn-primary"> 保 存</button>
				   </div>
               </form>
           </div><!--box box-default box-solid-->
        </section>   
           
        </div><!--row-->
    </section>
 </div>
  <!--主要内容结束-->
{%include file="index.footer.tpl.php"%}
 <script>
  $(function() {
    $( ".time" ).datepicker({
		 changeMonth: true,
	     changeYear: true,
		 dateFormat: "yy-mm-dd",
    });
  });
  </script>
<script language="javascript">
    //窗口表格增加一行
    function addNewRow(){
        var tabObj=document.getElementById("myTab");//获取添加数据的表格
        var rowsNum = tabObj.rows.length;  //获取当前行数
        var colsNum=tabObj.rows[rowsNum-1].cells.length;//获取行的列数
        var myNewRow = tabObj.insertRow(rowsNum);//插入新行
        var newTdObj1=myNewRow.insertCell(0);
        newTdObj1.innerHTML="<input type='checkbox' name='chkArr' id='chkArr' "+rowsNum+" />";
        var newTdObj2=myNewRow.insertCell(1);
        newTdObj2.innerHTML="<input type='text' class='form-control' name='data["+rowsNum+"][open_week_num]' value='' size='3' />";
        var newTdObj3=myNewRow.insertCell(2);
        newTdObj3.innerHTML="<select class='form-control' style='padding:0px; width:100px;' name='data["+rowsNum+"][staff_id]'"+rowsNum+">" + "{%foreach from=$staff_list key=key item=value%}<option value='{%$value.staff_id%}'> {%$value.staff_name%}</option>{%/foreach%}</select>";
        var newTdObj4=myNewRow.insertCell(3);
        newTdObj4.innerHTML="<input type='text' class='form-control time' name='data["+rowsNum+"][open_time]' value=''/>";
        var newTdObj5=myNewRow.insertCell(4);
        newTdObj5.innerHTML="<input type='text' class='form-control' name='data["+rowsNum+"][open_num]' value='' size='4'/>";
        var newTdObj6=myNewRow.insertCell(5);
        newTdObj6.innerHTML="<select class='form-control' style='padding:0px; width:110px;'  name='data["+rowsNum+"][class_id]'"+rowsNum+" >{%foreach from=$class_list key=key item=value%} <option value='{%$value.class_id%}'>{%$value.class_name%}</option>{%/foreach%}</select>";
        var newTdObj7=myNewRow.insertCell(6);
        newTdObj7.innerHTML="<input type='text' name='data["+rowsNum+"][open_content]' class='form-control' value=''/>";
        var newTdObj8=myNewRow.insertCell(7);
        newTdObj8.innerHTML="<select class='form-control' name='data["+rowsNum+"][subject_id]' style='padding:0px; width:120px;' name='nodeper'"+rowsNum+" >{%foreach from=$subject_list key=key item=value%} <option value='{%$value.subject_id%}'>{%$value.subject_name%}</option>{%/foreach%}</select>";
        var newTdObj9=myNewRow.insertCell(8);
        newTdObj9.innerHTML="<textarea class='form-control' name='data["+rowsNum+"][open_remark]' rows='1'></textarea>";

        $( ".time" ).datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: "mm-dd",
        });

    }
    //窗口表格删除一行
    function removeRow(){
        var chkObj=document.getElementsByName("chkArr");
        var tabObj=document.getElementById("myTab");
        for(var k=0;k<chkObj.length;k++){
            if(chkObj[k].checked){
                if($(".aim").eq(k).val()){
                    $.get("index.php?a=open.opendel",{open_id:$(".aim").eq(k).val()});
                }
                tabObj.deleteRow(k+1);
                k=-1;
            }
        }
    }
</script>